home *** CD-ROM | disk | FTP | other *** search
- // ===========================================================================
- // CDocDemoApp.cp ©1994 Metrowerks Inc. All rights reserved.
- // ===========================================================================
- //
- // A simple Application class which manages text documents.
-
- #include <StandardFile.h>
-
- #include <LApplication.h>
- #include <LGrowZone.h>
- #include <LWindow.h>
- #include <LScroller.h>
- #include <LPrintout.h>
- #include <LPlaceHolder.h>
-
- #include <UMemoryMgr.h>
- #include <UDrawingState.h>
- #include <URegistrar.h>
- #include <UDesktop.h>
-
- #include "CDocDemoApp.h"
- #include "CTextDoc.h"
- #include "CDirtyText.h"
-
- // the following is added for speech recognition
- #include "CDocSpeech.h"
- extern CDocSpeech *gDocSpeechObj;
- Boolean gHasSpeechRecog;
-
-
- // ===========================================================================
- // • Main Program
- // ===========================================================================
-
- void main(void)
- {
- // Set Debugging options
- SetDebugThrow_(debugAction_Alert);
- SetDebugSignal_(debugAction_Alert);
-
- InitializeHeap(3); // Initialize Memory Manager
- // Parameter is number of Master Pointer
- // blocks to allocate
-
- // Initialize standard Toolbox managers
- UQDGlobals::InitializeToolbox(&qd);
-
- new LGrowZone(20000); // Install a GrowZone function to catch
- // low memory situations.
- // Parameter is size of reserve memory
- // block to allocated. The first time
- // the GrowZone function is called,
- // there will be at least this much
- // memory left (so you'll have enough
- // memory to alert the user or finish
- // what you are doing).
-
- CDocDemoApp theApp; // Create instance of your Application
- theApp.Run(); // class and run it
- }
-
-
- // ===========================================================================
- // • CDocDemoApp Class
- // ===========================================================================
-
- // ---------------------------------------------------------------------------
- // • CDocDemoApp
- // ---------------------------------------------------------------------------
- // Constructor
-
- CDocDemoApp::CDocDemoApp()
- {
- // Register classes for objects created from 'PPob' resources
- URegistrar::RegisterClass(LWindow::class_ID, (ClassCreatorFunc) LWindow::CreateWindowStream);
- URegistrar::RegisterClass(LScroller::class_ID, (ClassCreatorFunc) LScroller::CreateScrollerStream);
- URegistrar::RegisterClass(LPlaceHolder::class_ID, (ClassCreatorFunc) LPlaceHolder::CreatePlaceHolderStream);
- URegistrar::RegisterClass(LPrintout::class_ID, (ClassCreatorFunc) LPrintout::CreatePrintoutStream);
- URegistrar::RegisterClass(LView::class_ID, (ClassCreatorFunc) LView::CreateViewStream);
-
- URegistrar::RegisterClass('Dtxt', (ClassCreatorFunc) CDirtyText::CreateDirtyTextStream);
-
- //determine if Speech Recognition Manager is available;
- //if it is available, create a custom speech recognition object (CDocSpeech)
- long theAttrs;
- OSErr theErr;
-
- gHasSpeechRecog = false;
- theErr = ::Gestalt(gestaltSpeechRecognitionVersion, &theAttrs);
- //version must be at least 1.5.0 to support SRM API used here
- if (!theErr)
- if (theAttrs >= 0x00000150) {
- gHasSpeechRecog = true;
- gDocSpeechObj = new CDocSpeech(); //create a single instance of the CDocSpeech class
- }
- }
-
-
- // ---------------------------------------------------------------------------
- // • ~CDocDemoApp
- // ---------------------------------------------------------------------------
- // Destructor
-
- CDocDemoApp::~CDocDemoApp()
- {
- //shut down speech recognition, if it's running
- if (gHasSpeechRecog) {
- delete gDocSpeechObj;
- }
- }
-
-
- // ---------------------------------------------------------------------------
- // • ObeyCommand
- // ---------------------------------------------------------------------------
- // Respond to commands
-
- Boolean
- CDocDemoApp::ObeyCommand(
- CommandT inCommand,
- void *ioParam)
- {
- Boolean cmdHandled = true;
-
- switch (inCommand) {
-
- // +++ Add cases here for the commands you handle
- // Remember to add same cases to FindCommandStatus below
- // to enable/disable the menu items for the commands
-
- default:
- cmdHandled = LDocApplication::ObeyCommand(inCommand, ioParam);
- break;
- }
-
- return cmdHandled;
- }
-
-
- // ---------------------------------------------------------------------------
- // • FindCommandStatus
- // ---------------------------------------------------------------------------
- // Pass back status of a (menu) command
-
- void
- CDocDemoApp::FindCommandStatus(
- CommandT inCommand,
- Boolean &outEnabled,
- Boolean &outUsesMark,
- Char16 &outMark,
- Str255 outName)
- {
- outUsesMark = false;
-
- switch (inCommand) {
-
- // +++ Add cases here for the commands you handle
-
- default:
- LDocApplication::FindCommandStatus(inCommand, outEnabled, outUsesMark,
- outMark, outName);
- break;
- }
- }
-
-
- // ---------------------------------------------------------------------------
- // • OpenDocument
- // ---------------------------------------------------------------------------
- // Open a Document file
-
- void
- CDocDemoApp::OpenDocument(
- FSSpec *inMacFSSpec)
- {
- CTextDoc *theDoc = new CTextDoc(this, inMacFSSpec);
- }
-
-
- // ---------------------------------------------------------------------------
- // • MakeNewDocument
- // ---------------------------------------------------------------------------
- // Create a new Document
-
- LModelObject*
- CDocDemoApp::MakeNewDocument()
- {
- CTextDoc *theDoc = new CTextDoc(this, nil);
- return theDoc;
- }
-
-
- // ---------------------------------------------------------------------------
- // • ChooseDocument
- // ---------------------------------------------------------------------------
- // Prompt the user to select a document to open
-
- void
- CDocDemoApp::ChooseDocument()
- {
- StandardFileReply macFileReply;
- SFTypeList typeList;
-
- UDesktop::Deactivate();
- typeList[0] = 'TEXT';
- ::StandardGetFile(nil, 1, typeList, &macFileReply);
- UDesktop::Activate();
- if (macFileReply.sfGood) {
- OpenDocument(&macFileReply.sfFile);
- }
- }
-